Skip to content

Show correct extra item in sequence comparison diffs - #14906

Open
SemTiOne wants to merge 8 commits into
pytest-dev:mainfrom
SemTiOne:fix/13652-misleading-extra-item-message
Open

Show correct extra item in sequence comparison diffs#14906
SemTiOne wants to merge 8 commits into
pytest-dev:mainfrom
SemTiOne:fix/13652-misleading-extra-item-message

Conversation

@SemTiOne

@SemTiOne SemTiOne commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

pytest reported the wrong extra item when comparing sequences of different lengths. It printed the item past the end of the shorter side. The real extra item sat at the first differing index.
Before:

E     assert [1, 2, 3] == [1, 2, 0, 3]
E       At index 2 diff: 3 != 0
E       Right contains one more item: 3   (wrong: extra item is 0)

After:

E     Right contains one more item: 0

The fix finds a single inserted item by checking whether the tails after the first differing index align, offset by one. It corrects only the single-extra-item case. Multi-item length differences still use the previous "first extra item" message.

  • Include documentation when adding new features.
  • Include new tests or update existing tests when applicable.
  • Allow maintainers to push and squash when merging my commits. Please uncheck this if you prefer to squash the commits yourself.
  • Closes Misleading message "Right contains one more item" #13652
  • If AI agents were used, they are credited in Co-authored-by commit trailers.
  • Create a new changelog file in the changelog directory, with a name like <ISSUE NUMBER>.<TYPE>.rst. See changelog/README.rst for details.
  • Add yourself to AUTHORS in alphabetical order.

Co-authored-by: Claude <noreply@anthropic.com>
@psf-chronographer psf-chronographer Bot added the bot:chronographer:provided (automation) changelog entry is part of PR label Aug 19, 2026
@SemTiOne
SemTiOne marked this pull request as ready for review August 19, 2026 06:30
@SemTiOne

Copy link
Copy Markdown
Contributor Author

Hi @Zac-HD, could you take a look at this PR when you have a moment? Thank you for your time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot:chronographer:provided (automation) changelog entry is part of PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading message "Right contains one more item"

1 participant